package com.rongmai.db.model;


import lombok.Data;

/**
 * @ClassName BaseResult
 * @Description 基础结果值
 *
 * @author sunhaojie 3113751575@qq.com
 * @date 2016年8月21日 下午8:13:49
 */
@Data
public class BaseResult<T> extends TraceResult {
	
	/**
	 * 成功返回值常量
	 */
	public final static BaseResult SUCCESS = new BaseResult("200", "操作成功");

	public final static BaseResult TO_LOGIN = new BaseResult("401", "请登录");

	public final static BaseResult FAIL = new BaseResult("500", "系统异常");


	/**
	 * 错误码
	 */
	private String code;
	/**
	 * 错误信息
	 */
	private String message;
	
	/**
	 * 添加返回值
	 */
	private T data;



	public BaseResult() {
		
	}

	public BaseResult(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public static BaseResult succ() {
		BaseResult baseResult = new BaseResult();
		baseResult.code = SUCCESS.getCode();
		baseResult.message = SUCCESS.getMessage();
		return baseResult;
	}

	public static <T> BaseResult succ(T data) {
		BaseResult baseResult = new BaseResult();
		baseResult.code = SUCCESS.getCode();
		baseResult.message = SUCCESS.getMessage();
		baseResult.data = data;
		return baseResult;
	}

	public static BaseResult fail(String message) {
		BaseResult baseResult = new BaseResult();
		baseResult.code = FAIL.getCode();
		baseResult.message = message;
		return baseResult;
	}

}
